<?php
class SearchMenu{

    var $stone=array();
    var $jewelType=array();
}
session_start();

if ( $_SERVER['REQUEST_METHOD'] == "GET" ) {

    $link = mysql_connect('localhost', 'root', '1');
    if (!$link) {
        die('<br>Ошибка соединения: ' . mysql_error());
    }

    mysql_query ('SET NAMES utf8');
    mysql_query ('SET CHARACTER SET utf8');
    mysql_set_charset('utf8',$link);

    $db_selected = mysql_select_db('Melagrano', $link);

    $select="select `Вставка` from melagranoru.tconstgroupvstavki";
    $r = mysql_query($select,$link);

    for($i = mysql_num_rows($r); $i > 0 ; $i--) {
        $content[] = mysql_fetch_assoc($r);
    }
    $searchMenu=new SearchMenu();
    $searchMenu->stone=$content;

    $select="select Name from melagranoru.tconstnames";
    $r = mysql_query($select,$link);

    $content=array();
    for($i = mysql_num_rows($r); $i > 0 ; $i--) {
        $content[] = mysql_fetch_assoc($r);
    }

    $searchMenu->jewelType=$content;
    echo json_encode($searchMenu);
}
/** UPDATE or DELETE **/
else if ( $_SERVER['REQUEST_METHOD'] == "POST" ) {
//    $_SESSION['basket']="";
//    unset($_SESSION['basket']);
//    $_SESSION['basket']= array();
    if(!array_key_exists('basket', $_SESSION)){
        $_SESSION['basket']= array();
    }

    $var = json_decode($_SESSION[basket],true);
    $array[]=json_decode($_POST['model'],true);

    if(is_array($var) && is_array($array)){
        $array=array_merge($array,$var);
    }
    $_SESSION['basket']=json_encode($array);
    //json_decode($_POST['model'],true)
}

else {
    // Just return a model. Don't bother actually creating it and returning the new record
    $data = array( "id" => 1, "name" => "Joe Zim", "age" => 23 );
    // Encode it as JSON and ship it back
    echo json_encode($data);
}


?>